package com.tanhua.admin.task;

import com.tanhua.admin.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时任务
 */
@Component
public class AnalysisTask {

    @Autowired
    private AnalysisService analysisService;

    /**
     * 需求：每5秒打印
     * 方法：完成业务逻辑
     *     没有返回值，没有参数
     */
    @Scheduled(cron = "0/5 * * * * ?")
    public void analysis() {
        String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("当前时间："+now);
        try {
            //定时调用service统计数据，存入统计表
            analysisService.analysis();
           // analysisService.freezeDetail();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
